package com.kordar.admin.modular.sys.service;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kordar.admin.enums.CommonActive;
import com.kordar.admin.modular.sys.entity.DatasourceEntity;
import com.kordar.admin.modular.sys.mapper.DatasourceMapper;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Map;
import java.util.stream.Collectors;

@AllArgsConstructor
@DS("#kordardb")
@Service
public class DatasourceServiceImpl extends ServiceImpl<DatasourceMapper, DatasourceEntity> implements DatasourceService {

    private final DatasourceMapper datasourceMapper;

    @Override
    public Map<String, String> labels() {
        return datasourceMapper.selectList(
                new QueryWrapper<DatasourceEntity>()
                        .eq("active", CommonActive.OPEN.getCode())
        ).stream().collect(Collectors.toMap(DatasourceEntity::getName, DatasourceEntity::getDescription));
    }
}
